#region Copyright Jonathan Quiros

//	
// All rights are reserved. Reproduction or transmission in whole or in 
// part, in any form or by any means, electronic, mechanical or otherwise, 
// is prohibited without the prior written consent of the copyright owner.
//
// Filename: ActivationFormModelBinder.cs
//

#endregion

using System.Web.Mvc;
using Novagoal.Website.Models.Forms;

namespace Novagoal.Website.WebApp.ModelBinders
{
    public class ActivationFormModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = base.BindModel(controllerContext, bindingContext);
            var activationFormModel = model as ActivationFormModel;

            if (activationFormModel != null)
            {
                if (activationFormModel.Password != activationFormModel.Confirmation)
                {
                    bindingContext.ModelState.AddModelError("Confirmation", "Passwords do not match");
                }
            }

            return model;
        }
    }
}